﻿using System.Collections;
using System.Collections.Generic;
using Freedom.Common.Collections;

namespace Freedom.WinCommon.Collections
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class DictionaryCollection<T> : DictionaryCollectionBase<T> 
        where T : class, IIdentifiable
    {
        private readonly Hashtable _mapId = new Hashtable();

        /// <summary>
        /// Gets the by ID.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public T GetById(object id)
        {
            return (T)_mapId[id];
        }
        /// <summary>
        /// Reloads the specified items.
        /// </summary>
        /// <param name="items">The items.</param>
        protected override void SetItems(IEnumerable<T> items)
        {
            _mapId.Clear();
            foreach (var item in items)
            {
                _mapId.Add(item.Id, item);
            }

            base.SetItems(items);
        }
    }
}
